import routes from './router';

import Vue from 'vue';
import Router from 'vue-router';
import {cancelFetches} from '../common/request';
import common from '../common/common';
import { login } from '../api/login/index';
import { Toast} from 'vant';

Vue.use(Router);

const router = new Router({
  mode: 'history',
  routes
});

router.beforeEach(async(to, from, next) => {

  cancelFetches();

  // let userInfo = common.store.getUser();
  // if (!userInfo && to.path !== '/') {
  //   next('/');
  //   window.location.reload();
  //   return false;
  // }

  // if (!userInfo && to.path !== '/login') {
  //   return next('/login');
  // }
  // // TODO 如果进入的是'/'，则根据条件跳转到相应的首页
  // if (to.path === '/') { // 如果已登录去home
  //   return next('/common/home/index');
  // }
  return next();
});

router.afterEach(() => {

});

export default router;
